package d4_map;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 2024/6/6  Cjr Map集合方法的使用 17：56
 */
public class MapTest2 {
    public static void main(String[] args) {

        Map<String, Integer> map = new HashMap<>();
        map.put("小明",18);
        map.put("咪咪",11);
        map.put("调调",43);
        System.out.println(map);

        //1.public int size():获取集合的大小
        System.out.println(map.size());

        //2.public void clear():清空集合
       /* map.clear();
        System.out.println(map);*/

        //3.public boolean isEmpty():判断集合是否为空,为空返回true,反之!
        System.out.println(map.isEmpty());//true

        //4.public V get(Object key):根据键获取对应值
        System.out.println(map.get("小明"));

        //5.public V remove(Object key):根据键删除整个元素(删除键会返回键的值)
        System.out.println(map.remove("调调"));//43

        //6.public boolean containsKey(Object key): 判断是否包含某个键, 包含返回true,反之
        System.out.println(map.containsKey("小型"));//false
        System.out.println(map.containsKey("咪咪"));//true

        //7.public boolean containsValue(Object value): //判断是否包含某个值
        System.out.println(map.containsValue(11));//true
        System.out.println(map.containsValue(66));//false

        //8.public Set<K> keySet() 获取Map集合全部键
        System.out.println(map.keySet());

        //9.public Collection<V> values(): 获取Map集合的全部值
        System.out.println(map.values());

        //10.把其他Map集合的数据道人自己的集合中来
        Map<String,String> mapTest1 = new HashMap<>();
        mapTest1.put("张安","睡觉");
        mapTest1.put("小明","吃饭");
        mapTest1.put("小明","吃饭");

        Map<String,String> mapTest2 = new HashMap<>();
        mapTest2.put("张安","睡觉");
        mapTest2.put("小明","看电视");
        mapTest1.putAll(mapTest1);
        System.out.println(mapTest2);
        System.out.println(mapTest1);
        System.out.println();

        HashMap<String, Object> map1 = new HashMap<>();
        System.out.println(map1);




    }
}
